package com.examination.client.config;

import com.examination.client.interceptor.AuthenticationInterceptor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * @author: XiaoDong
 * @date: 2021-10-23 14:51
 * @description:
 */
@Configuration
public class WebConfigurer implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getAuthenticationInterceptor())
                .excludePathPatterns(AUTH_WHITELIST)
                .addPathPatterns("/**");
    }

   @Bean
    public AuthenticationInterceptor  getAuthenticationInterceptor(){
        return new AuthenticationInterceptor();
    }

    private static final String[] AUTH_WHITELIST;

    static {
        AUTH_WHITELIST = new String[]{
                "/swagger-resources/**",
                "/swagger-ui.html",
                "/v2/api-docs",
                "/webjars/**",
                "swagger-boostrap-ui",
                "/doc.html"
        };
    }

}